package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.StrategyCatalogQuery;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;

    /**
     * 查看所有攻略目录
     * @param qo
     * @return
     */
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") StrategyCatalogQuery qo, Model model){
        qo.setOrderBy("sc.sequence");
        PageInfo<StrategyCatalog> pageInfo = strategyCatalogService.query(qo);
        List<Strategy> strategies = strategyService.selectAll();
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("strategies",strategies);
        return "strategyCatalog/list";
    }

    /**
     * 保存或更新攻略目录
     * @param strategyCatalog
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return new JSONResult();
    }

    @RequestMapping("/selectByStrategyId")
    @ResponseBody
    public Object selectByStrategyId(Long strategyId){
        return strategyCatalogService.selectByStrategyId(strategyId);
    }

}
